# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-fifo
_rockname=fifo
_pkgname=fifo.lua
pkgver=0.2
pkgrel=2
pkgdesc="FIFO library for Lua"
url="https://github.com/daurnimator/fifo.lua"
arch="noarch"
license="MIT"
checkdepends="lua-busted"
source="$pkgname-$pkgver.tar.gz::https://github.com/daurnimator/$_pkgname/archive/$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

case "$CARCH" in
ppc64le|riscv64|loongarch64) _luajit="" ;;
*) checkdepends="$checkdepends luajit"; _luajit="jit" ;;
esac

_luaversions="5.1 5.2 5.3"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
	checkdepends="$checkdepends lua$_v lua$_v-busted"
done

check() {
	local lver; for lver in $_luaversions $_luajit; do
		msg "Testing on lua$lver"
		lua$lver /usr/bin/busted
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc $lver"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_rockname/$pkgver-1"

	cd "$builddir"
	install -D -m 644 fifo.lua "$subpkgdir"/usr/share/lua/$lver/fifo.lua

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
db2e0d2117c70ab0daa6e83141b95f198689e6568aab51e8300ca5577c1a517de249b9514ad8a3476239da3d9bceb699726ead913126817c0801f7ec5d419306  lua-fifo-0.2.tar.gz
"
